package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.Order;
import com.health.service.OrderService;
import com.health.utils.Constant;
import com.health.vo.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * t_order表
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 添加预约
     */
    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        //预约方式
        order.setOrderType(Constant.ORDER_TYPE_SELF);
        order.setOrderStatus(Constant.ORDER_STATUS_NO);

        //添加预约,返回预约id
        int orderId=orderService.add(order);

        return new Result(true,"预约添加成功",orderId);
    }
    /**
     * 查询是否重复预约
     */
    @PostMapping("/checkOrderDate")
    public Result checkOrderDate(@RequestBody Order order){

        int count=orderService.findCountByOrder(order);

        if (count>0){
            return new Result(false,"已预约过,无法再次预约");
        }
        return new Result(true,"预约信息正常");
    }

}
